package com.sr.service.impl;

import com.sr.ibase.IBaseService;
import com.sr.ibase.impl.BaseServiceImpl;
import com.sr.pojo.WType;
import com.sr.service.ITypeService;
import com.sr.vo.req.TypeReqVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author xiaochi
 * @date 2022/4/30 9:19
 * @desc TypeServiceImpl
 */
@Service
public class TypeServiceImpl extends BaseServiceImpl<WType> implements ITypeService {

    /**
     * 判断名称是否存在
     * @param reqVo
     * @return
     */
    public boolean hasExistsByName(TypeReqVo reqVo){
        IBaseService.Criteria<WType> criteria = this.createCriteria(WType.class);
        criteria.andEqualTo(WType::getName,reqVo.getName())
                .andNotEqualTo(WType::getId,!StringUtils.isEmpty(reqVo.getId()),reqVo.getId());
        return this.count(criteria) > 0;
    }
}
